<?php

namespace component\extend\stationmessage;

use app\bll\UserMessage as BllUserMessage;
use component\extend\Isms;
use Exception;

class Index implements Isms
{
    public function send(array $param = [])
    {
        if (
            isset($param['data']['recipient'])
            &&  $param['data']['recipient'] > 0
        ) {
            try {
                $bllUserMessage = new BllUserMessage();
                $msgData = [
                    'sender'    => isset($param['data']['sender']) ? $param['data']['sender'] : 0,
                    'recipient' => $param['data']['recipient'],
                    'title'     => $param['message']['title'],
                    'content'   => $param['message']['content'],
                    'link'      => isset($param['data']['link']) ? $param['data']['link'] : '',
                ];
                $bllUserMessage->add($msgData);
            } catch (Exception $ex) {
                throw $ex;
            }
        }
    }
}
